apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "single-redis-operator.fullname" . }}
  labels:
    {{- include "single-redis-operator.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "single-redis-operator.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "single-redis-operator.selectorLabels" . | nindent 8 }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "single-redis-operator.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: "operator"
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
          {{- if .Values.clusterScoped }}
            {{ if .Values.watchNamespace }}
            - name: WATCH_NAMESPACE
              value: "{{ .Values.watchNamespace }}"
            {{ else }}
            - name: WATCH_NAMESPACE
              value: ""
            {{ end }}
          {{ else }}
            {{ if .Values.watchNamespace }}
            - name: WATCH_NAMESPACE
              value: "{{ .Values.watchNamespace }}"
            {{ else }}
            - name: WATCH_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            {{ end }}
          {{ end }}
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: OPERATOR_NAME
              value: "single-redis-operator"
            - name: SENTRY_DSN
              value: "{{ .Values.sentry_dsn }}"
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
